package com.gurid.service.statistics.controller.admin;

import com.gurid.common.base.result.R;
import com.gurid.service.statistics.service.DailyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author Gurid
 * @since 2024-06-10
 */
@RestController
@RequestMapping("/admin/statistics/daily")
@Tag(name = "DailyController", description = "统计分析管理")
//@CrossOrigin
public class DailyController {

    @Autowired
    private DailyService dailyService;

    @Operation(summary = "生成统计记录")
    @PostMapping("create/{day}")
    public R createStatisticsByDay(
            @Parameter(description = "统计日期", required = true)
            @PathVariable String day) {
        dailyService.createStatisticsByDay(day);
        return R.ok().message("统计数据生成成功");
    }

    @Operation(summary = "展示统计记录")
    @GetMapping("show-chart/{begin}/{end}")
    public R showChart(
            @Parameter(description = "开始日期", required = true)
                @PathVariable String begin,
            @Parameter(description = "截止日期", required = true)
                @PathVariable String end) {
        Map<String, Map<String, Object>> map = dailyService.getChartData(begin, end);
        return R.ok().data("chartData", map);
    }
}
